/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package consumo.session;

import consumo.ejb.BasicSessionBean;
import consumo.entity.Cliente;
import consumo.entity.Concessionaria;
import consumo.entity.Contrato;
import consumo.entity.Tarifa;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

/**
 *
 * @author Carlos Taschetto
 */
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class ContratoSession extends BasicSessionBean {

    public Contrato getById(int id) {
        return getPojo(Contrato.class, id);
    }

    
    public List<Contrato> getAll(Cliente id){
        return  getList(Contrato.class, "Select c from Contrato c where c.cliente = ?1", id);
    }

    
    public List<Tarifa> getTipoTarifaByConce(Concessionaria  conce){
        return getList(Tarifa.class, "select c from Tarifa c where c.conce = ?1", conce);
    }

    /**
     * Insere uma nova Concessionaria
     * @param object
     * @return object
     */
    public Contrato save(Contrato object){
        getEm().persist(object);
        return object;
    }
    
    public Contrato set(Contrato object){
        getEm().merge(object);
        return object;
    }
    
    public void remove(Contrato object){
        removeEntity(object);
    }
    
 
}
